package cn.canxin.core.controller;

import java.io.IOException;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import cn.canxin.core.bean.Teacher.*;
import cn.canxin.core.service.TeacherBaseInfoService;
import org.codehaus.jackson.map.ObjectMapper;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * teacher信息管理
 *
 */
@Scope("prototype")
@Controller
@RequestMapping("/teacherController")
public class TeacherController {

    @Autowired
    TeacherBaseInfoService teacherBaseInfoService;

    @ResponseBody
	@RequestMapping(params = "saveTeacherBaseInfo",method = RequestMethod.POST)
	public Map saveTeacherBaseInfo(@RequestBody String params) throws IOException {

        ObjectMapper mapper = new ObjectMapper();
        TeacherBaseInfo teacherBaseInfo = mapper.readValue(params,TeacherBaseInfo.class);
        String id = teacherBaseInfoService.addTeacherBaseInfo(teacherBaseInfo);
		Map result = new HashMap();
		result.put("result","ok");
        result.put("id",id);
		return result;
	}

    @ResponseBody
    @RequestMapping(params = "saveTeacherGradutaionInfo",method = RequestMethod.POST)
    public Map saveTeacherGradutaionInfo(@RequestBody String params) throws IOException {
        ObjectMapper mapper = new ObjectMapper();
        TeacherBaseInfo teacherBaseInfo = mapper.readValue(params,TeacherBaseInfo.class);
        teacherBaseInfoService.updateTeacherBaseInfo(teacherBaseInfo);
        Map result = new HashMap();
        result.put("result","ok");
        result.put("id",teacherBaseInfo.getId());
        return result;
    }


    /**
     *  保存教师教学经验信息
      * @param params
     * @return
     * @throws IOException
     */
    @ResponseBody
    @RequestMapping(params = "saveTeacherExperienceInfo",method = RequestMethod.POST)
    public Map saveTeacherExperienceInfo(@RequestBody String params) throws IOException {
        ObjectMapper mapper = new ObjectMapper();
        TeacherExperienceInfo teacherExperienceInfo = mapper.readValue(params,TeacherExperienceInfo.class);
        teacherBaseInfoService.addTeacherExperienceInfo(teacherExperienceInfo);
        Map result = new HashMap();
        result.put("result","ok");
        return result;
    }

    /**
     * 保存教师相册
     * @param params
     * @return
     * @throws IOException
     */
    @ResponseBody
    @RequestMapping(params = "saveTeacherPicture",method = RequestMethod.POST)
    public Map saveTeacherPicture(@RequestBody String params) throws IOException {
        ObjectMapper mapper = new ObjectMapper();
        TeacherPicture teacherPicture = mapper.readValue(params,TeacherPicture.class);
        teacherBaseInfoService.addTeacherPicture(teacherPicture);
        Map result = new HashMap();
        result.put("result","ok");
        return result;
    }

    /**
     * 保存教师教学科目
     * @param params
     * @return
     * @throws IOException
     */
    @ResponseBody
    @RequestMapping(params = "saveTeacherSubjectInfo",method = RequestMethod.POST)
    public Map saveTeacherSubjectInfo(@RequestBody String params) throws IOException {
        ObjectMapper mapper = new ObjectMapper();
        TeacherSubjectInfo teacherSubjectInfo = mapper.readValue(params,TeacherSubjectInfo.class);
        teacherBaseInfoService.addTeacherSubjectInfo(teacherSubjectInfo);
        Map result = new HashMap();
        result.put("result","ok");
        return result;
    }

    /**
     * 保存教师教学时间
     * @param params
     * @return
     * @throws IOException
     */
    @ResponseBody
    @RequestMapping(params = "saveTeacherTeachingInfo",method = RequestMethod.POST)
    public Map saveTeacherTeachingInfo(@RequestBody String params) throws IOException {
        ObjectMapper mapper = new ObjectMapper();
        TeacherTeachingTimeInfo teacherTeachingTimeInfo = mapper.readValue(params,TeacherTeachingTimeInfo.class);
        teacherBaseInfoService.addTeacherTeachingTimeInfo(teacherTeachingTimeInfo);
        Map result = new HashMap();
        result.put("result","ok");
        return result;
    }

    @ResponseBody
    @RequestMapping(params = "updateTeacherBaseInfo",method = RequestMethod.POST)
    public Map updateTeacherBaseInfo(@RequestBody String params) throws IOException {
        ObjectMapper mapper = new ObjectMapper();
        TeacherBaseInfo teacherBaseInfo = mapper.readValue(params,TeacherBaseInfo.class);
        Map result = new HashMap();
        result.put("result","ok");
        result.put("result","id");
        return result;
    }

    @ResponseBody
    @RequestMapping(params = "updateTeacherGradutaionInfo",method = RequestMethod.POST)
    public Map updateTeacherGradutaionInfo(@RequestBody String params) throws IOException {
        ObjectMapper mapper = new ObjectMapper();
        TeacherBaseInfo teacherBaseInfo = mapper.readValue(params,TeacherBaseInfo.class);
        Map result = new HashMap();
        result.put("result","ok");
        result.put("result","id");
        return result;
    }

    @ResponseBody
    @RequestMapping(params = "getTeacherBaseInfoList",method = RequestMethod.GET)
    public Map getTeacherBaseInfoList(){
        Map result = new HashMap();
        result.put("data",teacherBaseInfoService.getTeacherBaseInfoList());
        result.put("result","ok");
        return result;
    }

    @ResponseBody
    @RequestMapping(params = "getTeacherBaseInfoById",method = RequestMethod.GET)
    public Map getTeacherBaseInfoList(@RequestParam String id){
        Map result = new HashMap();
        result.put("data",teacherBaseInfoService.getTeacherBaseInfoById(id));
        result.put("result","ok");
        return result;
    }

}
